package com.itheima.thread;

public class MyThread extends Thread {
    boolean flag = false; // 线程执行的退出标记

    @Override
    public void run() {
        while (!flag) {
            System.out.println("MyThread...run...");

        }
        System.out.println("MyThread...end...");
    }

    public static void main(String[] args) throws
            InterruptedException {
        // 创建MyThread对象
        MyThread t1 = new MyThread();
        t1.start();
        // 主线程休眠6秒
        Thread.sleep(1000);
        // 更改标记为true
        t1.setFlag(true);
        //t1.stop();
        // 主线程休眠6秒
        Thread.sleep(60000);

    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }
}
